<template>
  <div class="index" style="background-color: white; padding: 20px;">

    <div class="title" style="display: flex;justify-content: space-between; margin-bottom: 20px; width: 100%;">

      <div class="kflexbc" style="width: 100%;">
        <div>
          <router-link to="/myDistributor/managelist"><el-button type="danger" round>客户经理管理</el-button></router-link>
          <router-link style="margin-left: 15px;" to="/myDistributor/addfenzu"><el-button type="danger" plain
              round>分组管理</el-button></router-link>
          <router-link style="margin-left: 15px;" to="/myDistributor/addtag"><el-button type="danger" plain
              round>标签管理</el-button></router-link>
        </div>

        <div>
          <el-button type="danger" round @click="tianjia">添加分销商</el-button>
        </div>

      </div>
    </div>
    <div class="add">


      <div class="sousuo kflexc" style="margin-bottom: 20px;">
        <div class="bgh kflexc mr20">
          <div class="w80">店铺名</div>
          <el-input placeholder="分销商店铺名" v-model="search" class="input-with-select"></el-input>
        </div>
        <div class="bgh kflexc mr20">
          <div class="w80">屏蔽状态</div>
          <el-select v-model="is_shield_agent" clearable placeholder="选择屏蔽状态">
            <el-option label="已屏蔽" :value="1"></el-option>
            <el-option label="未屏蔽" :value="0"></el-option>
          </el-select>
        </div>
        <div class="bgh kflexc mr20">
          <div class="w80">客户经理</div>
          <el-select v-model="cm_id" filterable clearable placeholder="选择客户经理">
            <el-option v-for="(item,index) in listk" :key="index" :label="item.name" :value="item.id"></el-option>
          </el-select>
        </div>
        <div class="bgh kflexc mr20">
          <div class="w80">选择分组</div>
          <el-select v-model="group_id" filterable clearable placeholder="选择分组">
            <el-option v-for="(item,index) in fzlist" :key="index" :label="item.title" :value="item.id"></el-option>
          </el-select>
        </div>
        <div class="bgh kflexc mr20">
          <div class="w80">筛选标签</div>
          <el-select v-model="label_id" filterable clearable placeholder="筛选标签">
            <el-option v-for="(item,index) in alltag" :key="index" :label="item.title" :value="item.id"></el-option>
          </el-select>
        </div>
        <el-button type="danger" round @click="searchgo">搜索</el-button>
      </div>
    </div>


    <div class="kflexc sousuo" style="margin-bottom: 20px;">
      <div class="bgh kflexc mr20">
        <div class="w80" style="width: 120px;">批量修改分组</div>
        <el-select @change="changeallfz" v-model="allchangefz" clearable placeholder="批量修改分组">
          <el-option v-for="(item,index) in fzlist" :key="index" :label="item.title" :value="item.id"></el-option>
        </el-select>
      </div>
      <el-button class="mr20" type="danger" @click="edittag(2)" round>批量添加标签</el-button>
      <el-checkbox v-model="checked" @change="onlyseeme">只显示正在分销我商品的分销商</el-checkbox>
    </div>

    <div class="con" v-loading="loading">
      <el-table :data="list" :header-cell-style="{
            background:'#F4F4F4',
            color:'#7D8087'}" border @selection-change="handleSelectionChange" style="width: 100%">
        <el-table-column type="selection" align="center" width="55">
        </el-table-column>
        <el-table-column align="center" prop="nick_name" label="备注名">
          <template slot-scope="scope">
            {{scope.row.nick_name}}<i class="el-icon-edit" style="color:#409EFF; cursor: pointer; margin-left: 5px;"
              @click="fix1(scope.row.id)"></i>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="name" label="分销商店铺名">
        </el-table-column>
        <el-table-column align="center" prop="name" label="所属分组">
          <template slot="header">
            <div style="display: flex;align-items: center;justify-content: center; line-height: 20px;">
              所属分组
              <el-popover class="t_wen" style="margin-left: 10px;" placement="top-start" title="" width="500"
                trigger="hover" content="为代理商创建分组一个代理商只能属于一个分组，可用于快速设置佣金规则，商品可见等。">

                <i class="el-icon-question" style="color: #409EFF;"></i>

              </el-popover>
            </div>
          </template>
          <template slot-scope="scope">
            {{ scope.row.group_name }}
          </template>
        </el-table-column>
        <el-table-column align="center" prop="name" label="代理商标签">
          <template slot="header">
            <div style="display: flex;align-items: center;justify-content: center; line-height: 20px;">
              代理商标签
              <el-popover class="t_wen" style="margin-left: 10px;" placement="top-start" title="" width="500"
                trigger="hover" content="为代理商打标记，通过标签来快速筛选代理商例如：销量大，直播销售，激活率高等，可用于快速设置佣金规则，商品可见">
                <i class="el-icon-question" style="color: #409EFF;"></i>
              </el-popover>
            </div>
          </template>
          <template slot-scope="scope">
            <div style="display: flex;align-items: center;">
              <el-tooltip v-if='scope.row.label_names.length!=0' class="t_overcall" effect="dark"
                :content="(scope.row.label_names).toString()" placement="top">
                <div>{{ (scope.row.label_names).toString() }}</div>
              </el-tooltip>

              <i class="el-icon-edit" style="color:#409EFF; cursor: pointer; margin-left: 5px;"
                @click="edittag(1,scope.row.id,scope.row.label_names)"></i>
            </div>

          </template>
        </el-table-column>
        <el-table-column align="center" prop="is_shield_agent" label="分销商屏蔽">
          <template slot-scope="scope">
            <el-switch class="switch" v-model="scope.row.is_shield_agent" active-color="#FF5C3B"
              inactive-color="#C9C9C9" :active-value=1 :inactive-value=0 @change="pingbi(scope.row,$event,scope.$index)"
              active-text="已屏蔽" 　 inactive-text="未屏蔽">
            </el-switch>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="cm_name" label="客户经理">
          <template slot-scope="scope">
            {{scope.row.cm_name}}<i class="el-icon-edit" style="color:#409EFF; cursor: pointer; margin-left: 5px;"
              @click="fix2b(scope.row.id)"></i>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="notes" label="备注">
          <template slot-scope="scope">
            <div style="display: flex;align-items: center;">
              <el-tooltip class="t_overcall" effect="dark" :content="scope.row.notes" placement="top">
                <div>{{ scope.row.notes }}</div>
              </el-tooltip>
              <i class="el-icon-edit" style="color:#409EFF; cursor: pointer; margin-left: 5px;"
                @click="changebz(scope.row)"></i>
            </div>
          </template>
        </el-table-column>

        <el-table-column align="center" width="350px" label="操作">
          <template slot-scope="scope">
            <span style="color: #409EFF; margin-right: 20px; cursor: pointer;"
              @click="openfz(scope.row.id,scope.row.group_name)">修改分组</span>
              <span style="color: #409EFF; margin-right: 20px; cursor: pointer;"
                @click="copy2(scope.row)">复制秘钥</span>
            <span style="color: #409EFF; margin-right: 20px; cursor: pointer;"
              @click="opendetail(scope.row)">详细信息</span>
            <!-- <span style="color: #409EFF; margin-right: 20px; cursor: pointer;"></span> -->

            <el-dropdown class="t_more">
              <span class="el-dropdown-link">
                <span style="color: #409EFF; margin-right: 10px;" @click="opendetail(scope.row)">更多</span>
                <i style="color:#409EFF;" class="el-icon-caret-bottom el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item>
                  <div @click="seeshop(scope.row.child_shop_id)">查看分销商品</div>
                </el-dropdown-item>
                <el-dropdown-item>
                  <div @click="seeorder(scope.row.child_shop_id)">查看订单</div>
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>


          </template>
        </el-table-column>
      </el-table>

      <el-pagination background layout="total,prev, pager, next" :current-page="page"
        style="margin: 20px; text-align: right;" @current-change="fanye" :page-size="pagesize"
        :total="total"></el-pagination>
    </div>


    <el-dialog title="选择客户经理" :close-on-click-modal="false" center :visible.sync="dialog" width="400px">
      <div class="listk">
        <!-- <el-radio v-for="item in listk" :key="item.id" v-model="radio" :label="item.id">{{item.real_name}}
				</el-radio> -->
        <el-select v-model="radio" filterable placeholder="选择客户经理">
          <el-option v-for="(item,index) in listk" :key="index" :label="item.name" :value="item.id"></el-option>
        </el-select>
        <router-link to="/myDistributor/managelist"><el-button type="text" plain>客户经理管理</el-button></router-link>
      </div>
      <span slot="footer" class="dialog-footer">
        <!-- <el-button type="info" round @click="dialog = false">取 消</el-button> -->
        <el-button type="danger" style="background-color: #2974FF;" round @click="fix2">确 定</el-button>
      </span>
    </el-dialog>

    <el-dialog title="屏蔽确认" center :visible.sync="log" center width="660px">
      <div style="font-size: 18px; margin-bottom: 20px;" v-if="pingbiji == 1">确定要屏蔽分销商吗？</div>
      <div style="font-size: 18px; margin-bottom: 20px;" v-if="pingbiji == 0">确定取消屏蔽分销商吗？</div>
      <!-- <div style="font-size: 18px; margin-bottom: 20px;">确定要屏蔽分销商吗？</div> -->
      <!-- <div style="font-size: 16px;" class="kflexcc"><i class="el-icon-warning" style="font-size: 30px; color: #E6A23C; margin-right: 20px;"></i>警告:该屏蔽操作不可逆，一但屏蔽无法解除！</div> -->
      <span slot="footer" class="dialog-footer">

        <el-button type="danger" round @click="change_is_delivery" :disabled="num != 0">确认({{num}})</el-button>
        <el-button type="info" round @click="resetchange">取 消</el-button>
      </span>
    </el-dialog>
    <!-- 详细信息 -->
    <el-dialog center title="公司详情" :visible.sync="comdetailshow" :close-on-click-modal="false" width="500px">

      <div class="t_com_det_font">
        <div style="margin-bottom: 15px;">联系电话:
          <span v-if="openphone==''">{{ comdetailform.mobile }} </span>
          <span v-if="openphone!=''">{{ openphone }} </span>
          <img v-if="eyetype==1" @click="chooseeye(1)" class="t_eyes" src="../../../static/img/fxopeneye.png"
            style="width: 20px; margin-left: 10px; cursor: pointer;">
          <img v-if="eyetype==2" @click="chooseeye(2)" class="t_eyes" src="../../../static/img/fxcloseeye.png"
            style="width: 20px; margin-left: 10px; cursor: pointer;">
        </div>
        <div v-if="eyetype==2" style="margin-bottom: 15px;">
          <el-input v-model="checkpwd" placeholder="请输入密码"></el-input>
          <el-button style="margin-right: 20px;" type="danger" @click="showphonepwd" round>确定</el-button>
          <div style="color: #409EFF; margin-top: 10px;" @click="changeeyepwd">设置密码</div>
        </div>
      </div>
      <div class="t_com_det_font" style="margin-bottom: 15px;">店铺负责人:{{ comdetailform.real_name }}</div>
      <div class="t_com_det_font" style="margin-bottom: 15px;">公司名称:{{ comdetailform.com }}</div>

      <div style="text-align: center;">
        <el-button type="danger" round @click="comdetailshow = false">关闭</el-button>
      </div>
    </el-dialog>
    <!-- 设置查看密码 -->
    <el-dialog center title="设置分销信息查看密码" :close-on-click-modal="false" :visible.sync="isshowchangeeyepwd" width="400px">
      <el-input style="width: 100%;margin-bottom: 15px;" v-model="neweyepwd" placeholder="请输入密码"></el-input>
      <el-input style="width: 100%;margin-bottom: 25px;" v-model="againeyepwd" placeholder="再次输入密码"></el-input>

      <div style="text-align: center;">
        <el-button @click="isshowchangeeyepwd = false" round>取消</el-button>
        <el-button @click="uppwd" type="danger" round>确定</el-button>
      </div>
    </el-dialog>
    <!-- 标签 -->
    <el-dialog center title="" :close-on-click-modal="false" :visible.sync="istagwindshow" width="400px">
      <div slot="title" class="dialog-title">
        <span v-if="changebqtype==2">批量增加标签</span>
        <span v-else>编辑标签</span>
      </div>
      <div class="t_tagbox_con">
        <div @click="choosetag(index)" :class="{t_tag_box_lei:item.ischoose}" class="t_tag_box"
          v-for="(item,index) in alltag" :key="index">
          {{ item.title }}
        </div>
      </div>

      <div style="text-align: center;">
        <el-button type="danger" round @click="changetag">确定</el-button>
      </div>
    </el-dialog>
    <!-- 修改分组 -->
    <el-dialog center title="修改分组" :close-on-click-modal="false" :visible.sync="ischangefenzu" width="400px">

      <div class="t_changefz_sel">
        <el-select style="margin-bottom: 20px;" v-model="nowfz" placeholder="请选择分组">
          <el-option v-for="(item,index) in fzlist" :key="index" :label="item.title" :value="item.id"></el-option>
        </el-select>
      </div>


      <div style="text-align: center;">
        <el-button type="danger" round @click="changefz">确定</el-button>
      </div>
    </el-dialog>
    <!-- 修改分组后提醒 -->
    <el-dialog center title="提醒" :visible.sync="isshowfztips" width="600px">

      <div class="t_changefz_sel" style="margin-bottom: 20px;">
        调整用户分组并不会影响商品的可见设置和佣金规则制定，如需修改请自行前往设置修改
      </div>


      <div style="text-align: center;">
        <el-button type="danger" round @click="isshowfztips=false">关闭</el-button>
      </div>
    </el-dialog>
    <!-- 备注 -->
    <el-dialog center title="备注" :visible.sync="isshowbz" :close-on-click-modal="false" width="600px">
      <el-input type="textarea" placeholder="请输入内容" v-model="bztextarea" maxlength="100" show-word-limit rows="10">
      </el-input>

      <div style="text-align: center;margin-top: 15px;">
        <el-button type="danger" round @click="upbzbtn">确定</el-button>
      </div>
    </el-dialog>

    <!-- 添加分销商 -->
    <el-dialog center title="添加分销商" :close-on-click-modal="false" :visible.sync="fenxiaoshanglog" width="400px">
      <el-input style="width: 100%;margin-bottom: 15px;" v-model="fenxiaoshangall.name" placeholder="分销商店铺名"></el-input>
      <el-input style="width: 100%;margin-bottom: 15px;" v-model="fenxiaoshangall.remark_name" placeholder="备注名"></el-input>
      <el-input style="width: 100%;margin-bottom: 25px;" show-password v-model="fenxiaoshangall.password" placeholder="密码"></el-input>
      <div style="text-align: center;">
        <el-button @click="fenxiaoshanglog = false" round>取消</el-button>
        <el-button @click="fenxiaoshanggo" type="danger" round>确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import axios from 'axios'
  import top from '@/components/top.vue'
  import left from '@/components/left.vue'
  import foot from '@/components/foot.vue'
  export default {
    components: {
      "left": left,
      "top": top,
      "foot": foot
    },
    name: 'myDistributor',
    data() {
      return {
        fenxiaoshanglog:false,
        fenxiaoshangall:{
          name:"",
          remark_name:"",
          password:""
        },
        msg: "",
        id: "",

        loading: true,
        search: "",
        log: false,
        pingbiwho: "",
        pingbiji: "",
        money: "",
        total: 0,
        pagesize: 20,
        page: 1,
        list: "",
        shop_id: "",
        danxuans: [],
        quanxuana: false,
        quanxuans: [],
        dialog: false,
        radio: '1',
        listk: "",
        real_name: "",
        jlid: "",
        func_B02: false,
        checked: false,
        selling: 0,
        is_shield_agent: "",
        num: 5,
        daojishi: "",
        changei: "",
        comdetailshow: false,
        comdetailform: {},
        istagwindshow: false,
        alltag: [],
        ischangefenzu: false,
        fzoptions: [{
          value: '选项1',
          label: '黄金糕'
        }, {
          value: '选项2',
          label: '双皮奶'
        }, {
          value: '选项3',
          label: '蚵仔煎'
        }],
        nowfz: '',
        isshowfztips: false,
        qxarr: [],
        fzlist: [],
        allchangefz: '',
        group_id: '',
        label_id: '',
        cm_id: '',
        alingchangefz: '',
        changebqtype: null,
        changebqid: null,
        isshowbz: false,
        bzrow: '',
        bztextarea: '',
        eyetype: 1,
        checkpwd: '',
        isshowchangeeyepwd: false,
        neweyepwd: '',
        againeyepwd: '',
        openphone: ''
      }
    },
    beforeDestroy() {
      document.onkeydown = null
    },
    created() {
      //按回车键搜索
      var that = this;
      document.onkeydown = function(e) {
        var ev = document.all ? window.event : e;
        if (ev.keyCode == 13) {
          that.getlist();
        }
      };

      var user = JSON.parse(localStorage.getItem('USER'));
      this.user_func = user.functions
      for (var i in this.user_func) {
        if (this.user_func[i] != null) {
          var func_number = this.user_func[i].code
        }
        if (func_number.indexOf("B02") >= 0) {
          this.func_B02 = true
        }
      }

      var that = this
      //传进来的shopid
      if (this.$route.query.id) {
        this.shopid = this.$route.query.id
      }
      this.getlistk()
      this.getlist();
      //获取我的secret
      axios.get('/api/plan-market/shop/secret')
        .then(response => {
          this.msg = response.data.data
        })

      //获取自己的id
      var user = JSON.parse(localStorage.getItem('USER'));
      this.id = user.id
      axios.get('/api/plan-market/user/shop')
        .then(response => {
          if (response.data.msg.code == 0) {
            this.shop_id = response.data.data.shop_id
          } else {
            if (response.data.msg.code == 50401) {
              that.$router.push({
                path: "/login"
              });
              return false
            }
            that.$message.error(response.data.msg.info);
          }
        })
      //分组列表
      this.getfzlist()
      //标签列表
      this.getbqlist()
    },
    methods: {
      tianjia:function(){
        this.fenxiaoshangall = {
          name:"",
          remark_name:"",
          password:""
        }
        this.fenxiaoshanglog = true
      },
      fenxiaoshanggo:function(){
        axios.post('/api/plan-market/shop/add_distributor',this.fenxiaoshangall)
          .then(response => {
            if (response.data.msg.code == 0) {
              this.$message.success('操作成功');
              this.getlist()
              this.fenxiaoshanglog = false
            } else {
              this.$message.error(response.data.msg.info);
            }
          })
      },
      resetchange() {
        this.log = false
        if (this.pingbiji == 1) {
          this.list[this.changei].is_shield_agent = 0
        }
        if (this.pingbiji == 0) {
          this.list[this.changei].is_shield_agent = 1
        }
      },
      pingbi: function(item, ji, i) {
        this.changei = i
        this.pingbiji = ji
        this.pingbiwho = item.child_shop_id
        this.log = true


        clearInterval(this.daojishi)
        this.num = 5
        this.daojishi = setInterval(() => {
          if (this.num > 0) {
            this.num--
          }
        }, 1000)
      },
      change_is_delivery: function() {
        axios.post('/api/plan-market/partner/shield/agent', {
            child_shop_id: this.pingbiwho,
            is_shield_agent: this.pingbiji,
          })
          .then(response => {
            if (response.data.msg.code == 0) {
              this.$message.success('操作成功');
              this.getlist()
            } else {
              this.$message.error(response.data.msg.info);
            }
          })
        this.log = false
      },
      //只显示我分销商品的分销商
      onlyseeme() {
        if (this.checked) {
          this.selling = 1
        } else {
          this.selling = 0
        }
        this.getlist()
      },
      //修改备注名
      fix1: function(id) {
        this.$prompt('请输入备注名', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
        }).then(({
          value
        }) => {
          let that = this
          axios.post('/api/plan-market/partner/setpartner', {
              id: id,
              nick_name: value
            })
            .then(response => {
              if (response.data.msg.code == 0) {
                that.getlist();
              } else {
                that.$message.error(response.data.msg.info);
              }
            })
        })
      },
      //修改mobile
      fix3: function(id) {
        this.$prompt('请输入联系电话', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
        }).then(({
          value
        }) => {
          let that = this
          axios.post('/api/plan-market/partner/setpartner', {
              id: id,
              mobile: value
            })
            .then(response => {
              if (response.data.msg.code == 0) {
                that.getlist();
              } else {
                that.$message.error(response.data.msg.info);
              }
            })
        })
      },
      //修改partner
      fix4: function(id) {
        this.$prompt('请输入负责人', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
        }).then(({
          value
        }) => {
          let that = this
          axios.post('/api/plan-market/partner/setpartner', {
              id: id,
              partner: value
            })
            .then(response => {
              if (response.data.msg.code == 0) {
                that.getlist();
              } else {
                that.$message.error(response.data.msg.info);
              }
            })
        })
      },
      //修改company
      fix5: function(id) {
        this.$prompt('请输入公司名', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
        }).then(({
          value
        }) => {
          let that = this
          axios.post('/api/plan-market/partner/setpartner', {
              id: id,
              company: value
            })
            .then(response => {
              if (response.data.msg.code == 0) {
                that.getlist();
              } else {
                that.$message.error(response.data.msg.info);
              }
            })
        })
      },
      fix2b: function(id) {
        this.radio = ''
        this.jlid = id
        this.dialog = true
      },
      fix2: function() {
        var that = this
        axios.post('/api/plan-market/partner/setpartner', {
            cm_id: this.radio,
            id: this.jlid
          })
          .then(response => {
            if (response.data.msg.code == 0) {
              that.dialog = false
              that.loading = true
              that.getlist()
            } else {
              if (response.data.msg.code == 50401) {
                that.$router.push({
                  path: "/login"
                });
                return false
              }
              that.$message.error(response.data.msg.info);
            }
          })
      },
      updateCode() {
        let that = this
        this.$confirm('确认变更该代码么？更改代码后用户将不能通过之前的编码添加您，不影响已有的分销商', '提示', {
          confirmButtonText: '确认',
          cancelButtonText: '取消',
          dangerouslyUseHTMLString: true
        }).then(() => {
          axios.post('/api/plan-market/shop/secret/change')
            .then(response => {
              if (response.data.msg.code == 0) {
                axios.get('/api/plan-market/shop/secret')
                  .then(response => {
                    that.msg = response.data.data
                  })
              } else {
                that.$message.error(response.data.msg.info);
              }
            })
        })

      },
      soldout(id) {
        this.$confirm('是否继续删除?<div>【有情提醒】：为了您的安全，建议定期更换分销商代码</div>', '提示', {
          confirmButtonText: '继续删除',
          cancelButtonText: '我再想想',
          dangerouslyUseHTMLString: true
        }).then(() => {
          var that = this;
          var formData = new FormData();
          formData.append("child_shop_id", id);
          axios.post('/api/plan-market/partner/delete', formData)
            .then(response => {
              if (response.data.msg.code == 0) {
                this.$message.success('删除成功')
                this.getlist()
              } else {
                if (response.data.msg.code == 50401) {
                  that.$router.push({
                    path: "/login"
                  });
                  return false
                }
                that.$message.error(response.data.msg.info);
              }
            })
        }).catch(() => {
          // this.$message({
          //   type: 'info',
          //   message: '已取消操作'
          // });
        });
      },
      //全选的ids集合
      ids: function() {
        var checkids = [];
        for (var i in this.list) {
          checkids.push(this.list[i].child_shop_id);
        }
        this.quanxuans = checkids;
      },
      //点击全选
      quanxuan: function() {
        if (
          this.danxuans.length != this.quanxuans.length ||
          this.danxuans.length == 0
        ) {
          this.danxuans = this.quanxuans;
          this.quanxuana = true;
        } else {
          this.danxuans = [];
          this.quanxuana = false;
        }
      },
      //点击单选
      danxuan: function() {
        // this.choosearea.push(this.checkedarea)
        if (this.danxuans.length == this.quanxuans.length) {
          this.quanxuana = true;
        } else {
          this.quanxuana = false;
        }
      },
      //翻页
      fanye: function(page) {
        this.loading = true
        this.page = page
        this.getlist()
      },
      //跳转编辑佣金
      fixmoney: function(id) {
        this.$router.push({
          path: '/editMoney',
          query: {
            id: id
          }
        })
      },
      //跳转查看订单
      seeorder: function(id) {
        this.$router.push({
          path: '/order_question/orderOther',
          query: {
            id: id
          }
        })
      },
      seeshop: function(id) {
        this.$router.push({
          path: '/myDistributor/myDistributorshop',
          query: {
            id: id
          }
        })
      },
      //获取分销商
      getlist: function() {
        this.danxuans = [];
        this.quanxuana = false
        this.search = this.search.trim()
        var that = this;
        axios.get('/api/plan-market/partner/list?name=' + encodeURIComponent(this.search) + '&label_names=1&page=' +
            this
            .page + '&page_size=' + this.pagesize + '&selling=' + this.selling + '&is_shield_agent=' + this
            .is_shield_agent + '&group_id=' + this.group_id + '&label_id=' + this.label_id + '&cm_id=' + this.cm_id)
          .then(response => {
            if (response.data.msg.code == 0) {
              that.list = response.data.data.data
              that.total = response.data.data.total
              that.ids()
              that.loading = false

            } else {
              if (response.data.msg.code == 50401) {
                that.$router.push({
                  path: "/login"
                });
                return false
              }
              that.$message.error(response.data.msg.info);
            }
          })
      },
      setk: function() {
        var that = this
        axios.post('/api/plan-market/cm/add', {
            cm_id: this.radio,
            child_shop_ids: this.danxuans
          })
          .then(response => {
            if (response.data.msg.code == 0) {
              that.dialog = false
              that.loading = true
              that.getlist()
            } else {
              if (response.data.msg.code == 50401) {
                that.$router.push({
                  path: "/login"
                });
                return false
              }
              that.$message.error(response.data.msg.info);
            }
          })
      },
      //获取人员
      getlistk: function() {
        var that = this
        axios.get('/api/plan-market/user/userManagerList')
          .then(response => {
            if (response.data.msg.code == 0) {
              that.listk = response.data.data
            } else {
              if (response.data.msg.code == 50401) {
                that.$router.push({
                  path: "/login"
                });
                return false
              }
              that.$message.error(response.data.msg.info);
            }
          })
      },
      //复制
      copy: function() {
        var that = this
        const input = document.createElement('input');
        document.body.appendChild(input);
        input.setAttribute('value', window.location.origin + '/91haoka_platform/#/register?supplier_id=' + this.msg);
        input.select();
        if (document.execCommand('copy')) {
          document.execCommand('copy');
          that.$message({
            message: '复制成功',
            type: 'success'
          });
        }
        document.body.removeChild(input);
      },
      copy2: function(item) {
        var that = this
        const input = document.createElement('input');
        document.body.appendChild(input);
        input.setAttribute('value', item.aes_key);
        input.select();
        if (document.execCommand('copy')) {
          document.execCommand('copy');
          that.$message({
            message: '复制成功',
            type: 'success'
          });
        }
        document.body.removeChild(input);
      },
      //搜索
      searchgo: function() {
        this.page = 1
        this.loading = true
        this.getlist()
      },
      //查看详情
      opendetail(row) {
        this.comdetailshow = true
        this.comdetailform = row
        this.openphone = ''
        this.eyetype = 1
      },
      //确认修改标签
      changetag() {

        var from = {
          "ids": [],
          "label_ids": []
        }
        for (var x = 0; x < this.alltag.length; x++) {
          if (this.alltag[x].ischoose) {
            from.label_ids.push(this.alltag[x].id)
          }
        }

        if (this.changebqtype == 1) {
          //单个
          from.ids = this.changebqid
        } else {
          //批量
          for (var y = 0; y < this.qxarr.length; y++) {
            from.ids.push(this.qxarr[y].id)
          }
        }



        axios.post('/api/plan-market/reseller/label/config', from)
          .then(response => {
            if (response.data.msg.code == 0) {
              this.$message({
                type: 'success',
                message: '操作成功!'
              });
              this.istagwindshow = false
              this.getlist()
            } else {
              this.$message.error(response.data.msg.info);
            }
          })

      },
      //修改单个标签
      edittag(type, id, labelnames) {
        this.changebqtype = type
        this.changebqid = id
        if (type == 2) {
          //批量修改
          if (this.qxarr.length == 0) {
            this.$message.error('请选择要修改的数据');
            return
          }

        }

        this.istagwindshow = true
        for (var x = 0; x < this.alltag.length; x++) {
          var item = this.alltag[x]
          item.ischoose = false
          this.$set(this.alltag, x, item)
        }

        if (type == 1) {
          //单个修改
          for (var x = 0; x < this.alltag.length; x++) {
            for (var y = 0; y < labelnames.length; y++) {
              if (this.alltag[x].title == labelnames[y]) {
                var item = this.alltag[x]
                item.ischoose = true
                this.$set(this.alltag, x, item)
              }
            }
          }
        }


      },
      //选择标签
      choosetag(i) {
        if (this.alltag[i].ischoose) {
          var item = this.alltag[i]
          item.ischoose = false
          this.$set(this.alltag, i, item)
        } else {

          var item = this.alltag[i]
          item.ischoose = true
          this.$set(this.alltag, i, item)
        }
      },
      //确认修改分组
      changefz() {



        var from = {
          group_id: this.nowfz,
          ids: []
        }
        from.ids.push(this.alingchangefz)

        axios.post('/api/plan-market/reseller/group/config', from)
          .then(response => {
            if (response.data.msg.code == 0) {
              this.$message({
                type: 'success',
                message: '操作成功!'
              });
              this.ischangefenzu = false
              this.isshowfztips = true
              this.getlist()
            } else {
              this.$message.error(response.data.msg.info);
            }
          })



      },
      //打开分组
      openfz(id, group_name) {
        // this.nowfz
        this.nowfz = ''
        console.log(id, group_name)
        for (var x = 0; x < this.fzlist.length; x++) {
          if (this.fzlist[x].title == group_name) {
            this.nowfz = this.fzlist[x].id
          }
        }
        //单独修改
        this.ischangefenzu = true
        this.alingchangefz = id

      },
      //批量修改分组
      changeallfz(val) {
        //批量修改
        if (this.qxarr.length == 0) {
          this.allchangefz = ''
          this.$message.error('请选择要修改的数据');
          return
        }
        this.$confirm('是否确认修改?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {

          var from = {
            group_id: val,
            ids: []
          }
          for (var x = 0; x < this.qxarr.length; x++) {
            from.ids.push(this.qxarr[x].id)
          }

          console.log(from)
          axios.post('/api/plan-market/reseller/group/config', from)
            .then(response => {
              if (response.data.msg.code == 0) {
                this.$message({
                  type: 'success',
                  message: '操作成功!'
                });
                this.allchangefz = ''
                this.getlist()
              } else {
                this.$message.error(response.data.msg.info);
              }
            })




        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          });
          this.allchangefz = ''
        });
      },
      //多选
      handleSelectionChange(val) {
        console.log(val)
        this.qxarr = val
      },
      //分组列表
      getfzlist() {
        axios.get('/api/plan-market/reseller/group/list')
          .then(response => {
            if (response.data.msg.code == 0) {

              this.fzlist = response.data.data
            } else {
              this.$message.error(response.data.msg.info);
            }
          })
      },
      //标签列表
      getbqlist() {
        axios.get('/api/plan-market/reseller/label/list')
          .then(response => {
            if (response.data.msg.code == 0) {

              this.alltag = response.data.data
              for (var x = 0; x < this.alltag.length; x++) {
                this.alltag[x].ischoose = false
              }
              console.log(this.alltag)
            } else {
              this.$message.error(response.data.msg.info);
            }
          })
      },
      //打开备注
      changebz(row) {
        this.bzrow = row
        this.bztextarea = row.notes
        this.isshowbz = true
      },
      //提交备注
      upbzbtn() {
        axios.post('/api/plan-market/set/agent/notes', {
            child_shop_id: this.bzrow.child_shop_id,
            notes: this.bztextarea
          })
          .then(response => {
            if (response.data.msg.code == 0) {
              this.isshowbz = false
              this.getlist()
            } else {
              that.$message.error(response.data.msg.info);
            }
          })

      },
      //切换眼睛
      chooseeye(i) {
        if (i == 1) {
          this.eyetype = 2
        } else if (i == 2) {
          this.eyetype = 1
          this.openphone = ''
        }
      },
      //打开设置密码
      changeeyepwd() {
        this.isshowchangeeyepwd = true
        this.neweyepwd = ''
        this.againeyepwd = ''
      },
      //提交密码
      uppwd() {
        axios.post('/api/plan-market/reseller/pwd/set', {
            password: this.neweyepwd,
            password_confirmation: this.againeyepwd
          })
          .then(response => {
            if (response.data.msg.code == 0) {
              this.$message({
                message: '设置成功',
                type: 'success'
              });

              this.isshowchangeeyepwd = false
              this.checkphonenum(this.neweyepwd)
            } else {
              this.$message.error(response.data.msg.info);
            }
          })

      },
      //解密电话
      checkphonenum(pwd) {
        axios.post('/api/plan-market/reseller/phone/get', {
            password: pwd,
            child_shop_id: this.comdetailform.child_shop_id
          })
          .then(response => {
            if (response.data.msg.code == 0) {

              console.log(response.data.data)
              this.openphone = response.data.data
              this.checkpwd = ''
            } else {
              this.$message.error(response.data.msg.info);
            }
          })
      },
      //输入密码查看
      showphonepwd() {
        this.checkphonenum(this.checkpwd)
      },

      //下载识别码
      exportsbm() {
        axios.get('/api/plan-market/partner/code/export')
          .then(response => {
            if (response.data.msg.code == 0) {
              this.$router.push('/order_export2?type=47')
            } else {
              this.$message.error(response.data.msg.info);
            }
          })
      }
    }

  }
</script>
<style scoped lang="scss">
  @import "@/assets/zuixin.scss";

  /deep/.el-table th div {
    line-height: 20px !important;
  }

  /*  */
  /deep/.switch .el-switch__label {
    position: absolute;
    display: none;
    color: #fff !important;
  }

  /*打开时文字位置设置*/
  /deep/.switch .el-switch__label--right {
    z-index: 1;
  }

  /* 调整打开时文字的显示位子 */
  /deep/.switch .el-switch__label--right span {
    margin-left: 0px;
  }

  /*关闭时文字位置设置*/
  /deep/.switch .el-switch__label--left {
    z-index: 1;
  }

  /* 调整关闭时文字的显示位子 */
  /deep/.switch .el-switch__label--left span {
    margin-left: 24px;
  }

  /*显示文字*/
  /deep/.switch .el-switch__label.is-active {
    display: block;
  }

  /* 调整按钮的宽度 */
  /deep/.switch.el-switch .el-switch__core,
  .el-switch .el-switch__label {
    width: 70px !important;
    margin: 0;
    height: 26px;
  }

  /deep/.switch.el-switch {
    height: 26px;
  }

  /deep/.switch.el-switch .el-switch__core {
    border-radius: 15px;
  }

  /deep/ .switch.el-switch .el-switch__label * {
    font-size: 12px !important;


  }

  /deep/.switch.el-switch .el-switch__core:after {
    top: 2px;
    width: 20px;
    height: 20px;
  }

  /deep/.el-switch.is-checked .el-switch__core::after {
    margin-left: -22px
  }
</style>
